﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Churchtoolkit.Utils.RulesManager;
using Churchtoolkit.DataAccess.Entities;
using Churchtoolkit.Utils.BootStrapper;
using Microsoft.Practices.ServiceLocation;

namespace Churchtoolkit.Web.Shell.Services
{
    public class RulesService : IBootstrapperTask
    {
        #region IBootstrapperTask Members

        public void Execute()
        {
            IRulesManager rulesManager = ServiceLocator.Current.GetInstance<IRulesManager>();
            rulesManager.RegisterNowRule<Members>(EntityState.Inserting, m => m.CreationDate);
            rulesManager.RegisterNowRule<Members>(EntityState.Inserting, m => m.LastUpdateDate);
            rulesManager.RegisterNowRule<Members>(EntityState.Updating, m => m.LastUpdateDate);
            rulesManager.Register<Members>(EntityState.Inserting, m => m.IsActive = false);
            rulesManager.Register<Members>(EntityState.Inserting, m=> m.ImagePath=Guid.NewGuid().ToString()+"-Profile");
        }

        #endregion
    }
}
